Miscellaneous EViews program

Beta 

The following program estimates the betas of one price series versus an index of price series by several methods: OLS regression, rolling regression (or moving cov/variance), state space, and multivariate arch. 
' BETA.PRG (3/7/2007)
' Time varying beta 
' demonstrates several ways 
' to obtain beta between assets
'   1) constant beta
'   2) rolling beta by regression/moving cov/var
'   3) using state space
'   4) using multivariate ARCH
' Checked 3/20/2007

'change path to program path
%path = @runpath
cd %path

' load workfile
load fx.wf1

' dependent variables of series must be continuous
smpl @all
series y1 = @pch(index)
series y2 = @pch(jy)

'------------------------------------------------------------------------
' calculate the constant beta using OLS
'------------------------------------------------------------------------
smpl 1990 @last
equation constant_beta.ls y2 c y1
series beta_const=c(2)

'------------------------------------------------------------------------
'  calculating time varying beta with rolling regression
'  for a bi-variate case can use moving cov/var instead of 
'  OLS regression
'------------------------------------------------------------------------
!ssize = 200
series beta_roll=@movcov(y1,y2,!ssize)/@movvar(y1,!ssize)

' code for running a rolling regression:
' commented here

'!length = @obs(y1)
'equation roll_beta.ls y2 c y1
'show roll_beta

'for !i = 1  to  !length-!ssize+1 
'   smpl @first+!i-1 @first+!i+!ssize-2
'   equation roll_beta.ls y2 c y1
'   smpl @first+!i+!ssize-2 @first+!i+!ssize-2
'   beta_roll = roll_beta.@coefs(2)
'next

'------------------------------------------------------------------------
' calculate beta with State Space
'  via a time-varying coefficient for Y1
'------------------------------------------------------------------------
smpl 1990 @last
sspace ssbeta
ssbeta.append y2=c(1)+sv1*y1+[var=exp(c(2))]
ssbeta.append @state sv1 = sv1(-1)
ssbeta.ml
ssbeta.makestates beta_*
rename beta_sv1 beta_ss

'------------------------------------------------------------------------
' calculate beta with system ARCH
' by estimating the covariance and variance of 
' the two series using Multivariate ARCH
'------------------------------------------------------------------------
system arbeta
arbeta.append y1 = c(1) 
arbeta.append y2 = c(2)
arbeta.arch @Diagvech  c(indef)   arch(1,indef)   garch(1,indef)
arbeta.makegarch(name=arch)

series beta_arch = arch01_02/arch01

'------------------------------------------------------------------------
' display the different betas
'------------------------------------------------------------------------
group betas_ls_roll beta_const beta_roll
group betas_roll_ss_arch  beta_roll beta_ss beta_arch

show betas_ls_roll.line
show betas_roll_ss_arch.line